/**
 * 
 */
package com.cr.backbone.util;

import java.util.Locale;
import java.util.ResourceBundle;

/**
 * 国际化数据字典获取工具类
 * @project RaedNote
 * @version 1.0
 * @company
 * @fileType UtilsI18n UtilsI18n.java
 * @author xianghua.hu
 * @date 2012-6-5 
 */
/**
 * @author huxh
 * 
 */
public class UtilsDataDictI18n {
	
	private static final String DATA_DICT_FILE_BASE_NAME_FROM_CLASS="resources/datadict";
	
	
	
//	Locale locale =Locale.getDefault();
//	// 根据本地国家语言来获得classes路径下baseName为message的资源文件
//	ResourceBundle rb=ResourceBundle.getBundle(DATA_DICT_FILE_BASE_NAME_FROM_CLASS,locale);

	/**
	 * 显示本地支持语言
	 * 
	 * @methodDescribe
	 * @author xianghua.hu
	 * @date 2012-6-5
	 */
	public static void showLoacleLanguage() {
		Locale[] ls = Locale.getAvailableLocales();

		for (Locale local : ls) {
			System.out.println(local.getDisplayCountry() + " "
					+ local.getCountry());
			System.out.println(local.getDisplayLanguage() + " "
					+ local.getLanguage());
			System.out.println("----------");
		}
	}

	/**
	 * 根据key获取默认语言数据字典
	 * 默认本地语言:			localeDefault
	 * 默认本地文件baseName:	datadict
	 * @param key
	 * @return
	 * @author huxh
	 * @date 2012-6-5
	 */
	public static String getI18nString(String key) {
		// 获得key的值
		String text = UtilsI18n.getI18nStringDefault(DATA_DICT_FILE_BASE_NAME_FROM_CLASS, key);
		return text;
	}

	public static String getI18nString(String fileBaseNameUrl,String key,Object...arguments) {
		// 获得key的值
		String text = UtilsI18n.getI18nStringDefault(DATA_DICT_FILE_BASE_NAME_FROM_CLASS, key,arguments);
		return text;
	}

	
	public static void main(String[] args) {
		showLoacleLanguage();
		String key1="1";
		String key2="0";
		
		//测试：
		//1、 获取国际化资源文件
		//2、 本地语言切换
//		Locale(String language, String country);
		Locale newLocale=new Locale("en","US");
		Locale.setDefault(newLocale);
		System.out.println( UtilsDataDictI18n.getI18nString(key1) );
		System.out.println( UtilsDataDictI18n.getI18nString(key2) );
		
		Locale newLocale2=new Locale("zh","CN");
		Locale.setDefault(newLocale2);
		System.out.println( UtilsDataDictI18n.getI18nString(key1) );
		System.out.println( UtilsDataDictI18n.getI18nString(key2) );
		
	}
	
	
}
